/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tigris.jasmincc.implementation;

import org.tigris.jasmincc.Production;

/**
 * <strong>Syntax</strong><br />
 * <strong>grammar</strong> grammarName [<strong>dialectof</strong>
 * BaseGrammarName]<br /> { instantiation area } <br /> { grammarBody area }
 * 
 * @author Sam Huang
 * 
 */
public class GrammarDeclarationProduction extends AbstractProduction {

	protected Production dialectofProduction = null;

	protected Production instantiationProduction = null;

	protected Production grammarBodyProduction = null;

	public void parse() throws Exception {
		lexer.nexttok(false, KW_GRAMMAR);
		lexer.nexttok(false); // grammar name
		tk = lexer.nexttok(false);
		if (tk.equalsIgnoreCase(KW_DIALECTOF)) {
			lexer.backward(tk);
			dialectofProduction.setLexer(lexer);
			dialectofProduction.parse();
		}
		instantiationProduction.setLexer(lexer);
		instantiationProduction.parse();

		grammarBodyProduction.setLexer(lexer);
		grammarBodyProduction.parse();
	}

	/**
	 * @param dialectof
	 *            the dialectof to set
	 */
	public void setDialectofProduction(Production dialectofProduction) {
		this.dialectofProduction = dialectofProduction;
	}

	/**
	 * @param grammarBody
	 *            the grammarBody to set
	 */
	public void setGrammarBodyProduction(Production grammarBody) {
		this.grammarBodyProduction = grammarBody;
	}

	/**
	 * @param instantaionProduction
	 *            the instantaionProduction to set
	 */
	public void setInstantiationProduction(Production instantaionProduction) {
		this.instantiationProduction = instantaionProduction;
	}

}
